#include "timer.h"

Timer::Timer(QWidget *parent) :
    QLineEdit(parent)
{
    connect(&t,SIGNAL(timeout()),this,SLOT(addtime()));
    this->setAlignment(Qt::AlignCenter);
    this->setText("00:00:00.0");
}

void Timer::start()
{
    t.start(100);
}

void Timer::addtime()
{
        ttime+=1;
        s.sprintf("%02d:%02d:%02d.%d",ttime/36000,(ttime%36000)/600,(ttime%600)/10,ttime%10);
        this->setText(s);
}

void Timer::stop()
{
    t.stop();
}

void Timer::clean()
{
    ttime=0;
    this->setText("00:00:00.0");
}
int Timer::getTime() const
{
    return ttime;
}
void Timer::setTime(int tt)
{
    ttime=tt;
    s.sprintf("%02d:%02d:%02d.%d",ttime/36000,(ttime%36000)/600,(ttime%600)/10,ttime%10);
    this->setText(s);
}
